﻿using CSharp.ConsoleTools.ConHandlerEnums;
using CSharp.ConsoleTools.Properties;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharp.ConsoleTools
{
	public sealed class ConHandler
	{
		#region declares
		// singleton member
		static readonly ConHandler _instance = new ConHandler();

		// areas
        MenuHandler _menuHandler = MenuHandler.Instance;
        OutputHandler _outputHandler = OutputHandler.Instance;
		#endregion



		#region constructor
		//singleton private constructor
		private ConHandler()
		{
			_initClass();
		}
		#endregion



		#region private functions
		/// <summary>
		/// apply and verify settings
		/// </summary>
		private void _initClass()
		{
			try
			{
				//set console encoding
				Console.OutputEncoding = System.Text.Encoding.Unicode;

				//prepare window 
				Console.SetWindowSize(Settings.Default.ConsoleWindowWidth, Settings.Default.ConsoleWindowHeight);
				Console.BackgroundColor = Settings.Default.ConsoleBackground;
				Console.ForegroundColor = Settings.Default.ConsoleForeground;
				Console.Clear();

				//prepare menu area defaults
                Menu.InitMenu(new ConsoleArea());
                Menu.Area.TitleText = "Menu";
                Menu.Area.ShowTitle = true;

				//prepare output area
                Output.InitOutput(new ConsoleArea());
                Output.Area.TitleText = "Output";
                Output.Area.ShowTitle = true;
                Output.Area.BorderTop = Menu.Area.BorderHeight;
			}
			catch (Exception ex)
			{

				throw ex;
			}
		}
		#endregion



		#region properties
		// singleton instance getter
		public static ConHandler Instance { get { return _instance; } }
		#endregion



		#region methods
		public void Render()
		{
			Console.Clear();
            Menu.Render();
            Output.Render();
		}
		#endregion



		#region interface implementation
        public MenuHandler Menu { get { return _menuHandler; } }
        public OutputHandler Output { get { return _outputHandler; } }
		#endregion

	}
}
